﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Configuration;
using System.ComponentModel;

namespace outREACH.App_Code
{
    [DataObject]
    public class DevelopingCountries1
    {
          [DataObjectField(true, true)]
        public string developingCountries { get; set; }


        [DataObjectMethod(DataObjectMethodType.Select)]
        public static List<DevelopingCountries1> GetDevelopingCountries()
        {
            SqlConnection conn = null;
            conn = new SqlConnection();
            conn.ConnectionString = ConfigurationManager.ConnectionStrings["outreachdbConnectionString"].ConnectionString;
            conn.Open();
            SqlCommand comm = new SqlCommand();
            comm.Connection = conn;
            comm.CommandText = "select * from DevelopingCountries";
            SqlDataReader dr = comm.ExecuteReader();
            List<DevelopingCountries1> list = new List<DevelopingCountries1>();
            while (dr.Read())
            {
                DevelopingCountries1 udc = new DevelopingCountries1();
                udc.developingCountries = (String)dr["DevelopingCountries"];
                list.Add(udc);
            }
            return list;
        }


        public static List<DevelopingCountries1> ListAll()
        {

            List<DevelopingCountries1> results = new List<DevelopingCountries1>();
            SqlConnection conn = new SqlConnection();

            try
            {
                //do sql operation
                conn.ConnectionString = ConfigurationManager.ConnectionStrings["outreachdbConnectionString"].ConnectionString;
                conn.Open();
                SqlCommand comm = new SqlCommand();
                comm.Connection = conn;
                comm.CommandText = "Select * from DevelopingCountries";
                SqlDataReader dr = comm.ExecuteReader();
                while (dr.Read())
                {
                    DevelopingCountries1 udc = new DevelopingCountries1();
                    udc.developingCountries = (String)dr["developingCountries"];

                    results.Add(udc);


                }
                dr.Close();




            }
            catch (SqlException e)
            {
                /*if error we will throw exception to you */
                throw e;


            }
            finally
            {
                /*no matter if pass or fail, we need to
                 * close the database connection */

                conn.Close();

            }
            return results;
        }

        public static List<DevelopingCountries1> getDCList()
        {
            SqlConnection conn = null;
            List<DevelopingCountries1> result = new List<DevelopingCountries1>();

            try
            {
                conn = new SqlConnection();
                SqlCommand comm = new SqlCommand();
                conn.ConnectionString = ConfigurationManager.ConnectionStrings["outreachdbConnectionString"].ConnectionString;
                conn.Open();
                comm.Connection = conn;
                comm.CommandText = "Select * from DevelopingCountries";
                SqlDataReader dr = comm.ExecuteReader();
                while (dr.Read())
                {
                    DevelopingCountries1 dc = new DevelopingCountries1();
                    dc.developingCountries = (string)dr["developingCountries"];
                    result.Add(dc);
                }
                dr.Close();
            }
            catch (SqlException ex)
            {
                throw ex;
            }
            finally
            {
                conn.Close();
            }
            return result;
        }

        public string d { get; set; }

        public System.Web.UI.WebControls.ListItem DevelopingCountries { get; set; }
    }
}